package com.qys.livesMall.shop.event.handle.service;

import com.qys.livesMall.common.constants.Constants;
import com.qys.livesMall.shop.event.handle.BaseHandler;
import com.qys.livesMall.shop.event.shop.pojo.OpenShopEventPojo;
import com.qys.livesMall.shop.modal.entity.H2ShopStatisticsInfo;
import com.qys.livesMall.shop.modal.entity.ShopEventInfo;
import com.qys.livesMall.shop.modal.entity.ShopStatisticsTeam;
import com.qys.livesMall.shop.service.H2ShopStatisticsInfoService;
import com.qys.livesMall.shop.service.ShopStatisticsTeamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @menu ShopBaseServer
 * @date 2023/11/03 10:09
 */
@Service
public class ShopBaseServer implements BaseHandler<OpenShopEventPojo> {

    @Autowired
    private H2ShopStatisticsInfoService shopStatisticsInfoService;
    @Autowired
    private ShopStatisticsTeamService shopStatisticsTeamService;

    @Override
    public void correct(Long shopId) {
        //生成店铺统计表
        H2ShopStatisticsInfo shopStatisticsInfo=shopStatisticsInfoService.getByShopId(shopId);
        if (shopStatisticsInfo!=null){
            return;
        }
        shopStatisticsInfo=new H2ShopStatisticsInfo();
        shopStatisticsInfo.setShopId(shopId);
        shopStatisticsInfo.setExpire(Constants.YesNoInt.YES);
        shopStatisticsInfoService.save(shopStatisticsInfo);
    }


    @Override
    public void handle(ShopEventInfo<OpenShopEventPojo> info) {
        //生成店铺统计表
        H2ShopStatisticsInfo shopStatisticsInfo=shopStatisticsInfoService.getByShopId(info.getShopId());
        if (shopStatisticsInfo!=null){
            return;
        }
        shopStatisticsInfo=new H2ShopStatisticsInfo();
        shopStatisticsInfo.setShopId(info.getShopId());
        shopStatisticsInfo.setExpire(Constants.YesNoInt.YES);
        shopStatisticsInfoService.save(shopStatisticsInfo);

        //生成团队统计表
        ShopStatisticsTeam team=shopStatisticsTeamService.getByShopId(info.getShopId());
        if (team!=null){
            return;
        }
        team=new ShopStatisticsTeam();
        team.setShopId(info.getShopId());
        shopStatisticsTeamService.save(team);
    }
}

